# Maintainer: Leo <thinkabit.ukim@gmail.com>
_pkgname=filesize
pkgname=lua-$_pkgname
pkgver=0.1.1
pkgrel=2
pkgdesc="Generate human readable string describing the size of files"
url="https://github.com/starius/lua-filesize"
arch="all"
license="MIT"
source="$_pkgname-$pkgver.tar.gz::https://github.com/starius/lua-filesize/archive/$pkgver.tar.gz"

_luaversions="5.1 5.2 5.3 5.4"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-$_pkgname:split_${_v/./_}"
done

package() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver..."

		mkdir -p "$pkgdir"/usr/share/lua/$lver
		install -Dm644 src/filesize/filesize.lua \
			"$pkgdir"/usr/share/lua/$lver/filesize.lua
	done
}

_split() {
	local d= _ver=$1
	pkgdesc="$pkgdesc for Lua $_ver"
	install_if="lua$_ver $pkgname=$pkgver-r$pkgrel"
	depends=
	for d in usr/lib/lua usr/share/lua; do
		if [ -d "$pkgdir"/$d/$_ver ]; then
			mkdir -p "$subpkgdir"/$d
			mv "$pkgdir"/$d/$_ver "$subpkgdir"/$d/
		fi
	done
}

split_5_1() { _split 5.1 ; }
split_5_2() { _split 5.2 ; }
split_5_3() { _split 5.3 ; }
split_5_4() { _split 5.4 ; }

sha512sums="e1ea3d922b7e58e79a499d5e612367d22fa751348e8f253eef3145b5b440de1dcccaa2bbd66a28da6472dc73736c7de2798384355f88c77abf0501234bd261e3  filesize-0.1.1.tar.gz"
